package com.service.atf.base.type;

import com.service.atf.base.exception.TFException;
import com.service.atf.base.utils.ATFConstants;

import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * User: luotao
 * Date: 12-2-25
 * Time: 12:49
 */
public class BuffWriterCommon {


    public static MappedByteBuffer createWriteBuff(FileChannel fileChannel, int start, long length) {
        try {
            return fileChannel.map(FileChannel.MapMode.READ_WRITE, start
                    , length);
        } catch (IOException e) {
            throw new TFException(ATFConstants.ATF_TF_CRETE_RW_ERR, "������дӳ�����");
        }
    }

    public static MappedByteBuffer createReadBuff(FileChannel fileChannel, int start, long length) {
        try {
            return fileChannel.map(FileChannel.MapMode.READ_ONLY, start
                    , length);
        } catch (IOException e) {
            throw new TFException(ATFConstants.ATF_TF_CRETE_READ_ONLY_ERR, "����ֻ��ӳ�����");
        }
    }
}
